package com.bw.zyk.zhanggm.product.job;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;
import com.bw.zyk.zhanggm.product.config.AlipayConfig;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.UUID;

@Slf4j
@Component
public class JobTest {

    @Autowired
    KafkaTemplate kafkaTemplate;

    @XxlJob("demoJobHandler")
    public void test() {
        kafkaTemplate.send("2109test", "test");
        log.info("消息发送成功");
    }

    @XxlJob("demoJobHandler1")
    public void test1() throws AlipayApiException {
        //调用支付宝下单接口
        AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id,AlipayConfig.merchant_private_key,"json","GBK",AlipayConfig.alipay_public_key,"RSA2");
        AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
        //异步接收地址，仅支持http/https，公网可访问
        request.setNotifyUrl("");
        //同步跳转地址，仅支持http/https
        request.setReturnUrl(AlipayConfig.return_url);
        /******必传参数******/
        JSONObject bizContent = new JSONObject();
        //商户订单号，商家自定义，保持唯一性
        UUID uuid = UUID.randomUUID();
        bizContent.put("out_trade_no", uuid);
        //支付金额，最小值0.01元
        bizContent.put("total_amount", "1.01");
        //订单标题，不可使用特殊符号
        bizContent.put("subject", "测试订单");
        //电脑网站支付场景固定传值FAST_INSTANT_TRADE_PAY
        bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY");
        request.setBizContent(bizContent.toString());
        AlipayTradePagePayResponse response = alipayClient.pageExecute(request,"POST");
        // 如果需要返回GET请求，请使用
        // AlipayTradePagePayResponse response = alipayClient.pageExecute(request,"GET");
        String pageRedirectionData = response.getBody();
        log.info(pageRedirectionData);
        if(response.isSuccess()){
            log.info(pageRedirectionData);
        }
    }


}
